package pers.cocoadel.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.cocoadel.springcloud.domain.Storage;
import pers.cocoadel.springcloud.entities.CommonResult;
import pers.cocoadel.springcloud.service.StorageService;

@RestController
public class StorageController
{
    private final StorageService storageService;

    @Autowired
    public StorageController(StorageService storageService)
    {
        this.storageService = storageService;
    }

    @PostMapping("/storage/decrease")
    public CommonResult<Storage> decrease(@RequestParam("productId") Long productId,
                                          @RequestParam("count") Integer count)
    {
        storageService.decrease(productId, count);
        return new CommonResult<>(200, "OK", null);
    }
}
